<?php

namespace app\admin\controller\demo;

use app\admin\service\demo\DemoService;
use app\common\controller\CommonBaseController;
use app\common\utils\ApiReturn;
use app\common\utils\MyLog;
use app\common\validate\demo\DemoValidate;
use app\Request;
use Error;
use Exception;

class Demo extends CommonBaseController
{
    /**
     * 获取 Demo 列表
     * 注意, 应该对此处的整块代码使用 try...catch... 包裹
     * @param Request $request
     * @return void
     */
    public function getDemoList(Request $request)
    {
        try{
            //参数校验
            validate(DemoValidate::class)->scene('getList')->check($this->params); // 场景验证
            //调用Service层处理业务逻辑
            $list = DemoService::getDemoList($this->params);
            MyLog::record()->info("成功返回");
            //统一的成功返回方法
            ApiReturn::retSuccess($list);
        }catch (Exception | Error $e){
            //异常或错误 被捕获到以后,调用统一方法处理
            ApiReturn::retError($e);
        }
    }
}